package com.how.diaryfriend.data;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;


@Database(entities = {Diary.class},version = 1,exportSchema = false)
public abstract class DiaryDatabase extends RoomDatabase {
    private static DiaryDatabase INSTANCE;
    static synchronized DiaryDatabase getDatabase(Context context) {
        if (INSTANCE == null) {
            INSTANCE = Room.databaseBuilder(context.getApplicationContext(),DiaryDatabase.class,"diary")
                    //.fallbackToDestructiveMigration()
//                    .addMigrations(MIGRATION_3_4)
                    .build();
        }
        return INSTANCE;
    }
    public abstract DiaryDao getDiaryDao();

    static final Migration MIGRATION_2_3 = new Migration(2,3) {
        @Override
        public void migrate(@NonNull SupportSQLiteDatabase database) {
            database.execSQL("ALTER TABLE word ADD COLUMN bar_data INTEGER NOT NULL DEFAULT 1");
        }
    };
}
